// rollup.config.js
import resolve from "rollup-plugin-node-resolve"
import vue from "rollup-plugin-vue"
import babel from "@rollup/plugin-babel"
import commonjs from "@rollup/plugin-commonjs"
import { terser } from "rollup-plugin-terser";
import css from 'rollup-plugin-css-only' // 处理css文件插件
import CleanCSS from 'clean-css' // 压缩css
import { writeFileSync } from 'fs' // 写文件


const config = {
  input: "./index.js", // 必须，入口文件
  output: { // 必须，输出文件 (如果要输出多个，可以是一个数组)
    exports: "named", // 输出多个文件
    globals: {
      vue: "Vue" // 告诉rollup全局变量Vue即是vue
    },
    name: 'file'
  },
  external: ['vue'],
  plugins: [ // 引入的插件在这里配置
    resolve(),
    vue({
      css: false,
      compileTemplate: true
    }),
    babel({
      exclude: "**/node_modules/**"
    }),
    commonjs(),
    terser(), // 代码压缩
    css({
      output(style) {
        // 压缩 css 写入 css
        writeFileSync('dist/index.css', new CleanCSS().minify(style).styles)
      }
    }),
  ]
}

export default config

/**
 * 参考文档
https://blog.csdn.net/SKS_IT/article/details/118006273
https://blog.csdn.net/kalrase/article/details/110186870
https://www.jianshu.com/p/464e2bb58eda?utm_campaign=haruki&utm_content=note&utm_medium=seo_notes&utm_source=recommendation
https://juejin.cn/post/6960216584241545224#heading-0
https://segmentfault.com/a/1190000019744295 
https://juejin.cn/post/6934698510436859912
* 
 * */